package com.transfer.common;

import java.io.File;
import java.util.concurrent.Callable;

import com.transfer.utils.MD5FileUtil;

public class VerifyMD5Task implements Callable<Boolean>, SuspendInterface {

  private String fileName;
  private String MD5;
  private boolean shutdownRequested=false;
  
  public VerifyMD5Task(String fileName, String MD5) {
    this.fileName = fileName;
    this.MD5 = MD5;
  }

  public Boolean call() throws Exception {
    File file = new File(fileName);
    String md5 = MD5FileUtil.fileMD5AndCanSuspend(file, shutdownRequested);
    if(shutdownRequested)
      return false;
    if (md5.equals(this.MD5))
      return true;
    return false;
  }

  public void shutdownRequest() {
    // TODO Auto-generated method stub
    shutdownRequested = true;
  }

}
